import {useRequest} from "ahooks";
import {findByIdFactory, isSuccessRes} from "@/types/common";
import {GetShops,} from '@/api/productionStat'

export const useShops = () => {
  const req = useRequest<{ label: string, value: number }[]>(
    () => GetShops({inKey: ''}).then((res) => {
      if (isSuccessRes(res)) {
        return res.Result.Items.map(e =>
          ({
            label: e.Name,
            value: e.ShopId
          })
        )
      }
    }),
    {
      cacheKey: 'useShops',
      loadingDelay: 1000,
      cacheTime: -1,
      staleTime: -1
    },
  );
  const {data, loading} = req

  return {
    req,
    selectProps: {
      options: data,
      loading: loading
    },
    findById: findByIdFactory(data)
  }
}
